package com.franklin.validation.core.argument.impl.string;

import com.franklin.validation.core.annotations.ParamCheck;
import com.franklin.validation.core.annotations.Resolver;
import com.franklin.validation.core.annotations.WebFluxFormDataComponent;
import com.franklin.validation.core.constants.Constants;
import com.franklin.validation.core.entity.CheckFormEntity;
import com.franklin.validation.core.utils.ReflectionUtil;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/15 17:00
 */
@Resolver
@WebFluxFormDataComponent
public class StringResolverResult extends AbstractStringResolverResult<String> {
    @Override
    public String onError(CheckFormEntity input) {
        ParamCheck paramCheck = input.getParamCheck();
        if (ReflectionUtil.isSystemDefaultValue(paramCheck.defaultValue())){
            return Constants.EMPTY;
        }
        return paramCheck.defaultValue();
    }

    @Override
    public String getResult(CheckFormEntity input) {
        return this.getStringValue(input.getValues());
    }

}
